function secret(){
    $.ajax({
        url:'/user/build_google_secret.json',
        type:'get',
        dataType:'json',
        contentType:'application/json;charset=UTF-8',
        success:function(data){
            console.log(data);
            $('.qrcodeBase64').attr('src','data:image/png;base64,'+data.data.model.qrcodeBase64)
            $('.secret').val(data.data.model.secret);
        },
        error:function(msg){
            $('.err-info').html(JSON.parse(msg.responseText).errors[0].msg);
        }
    });
}
secret();


$('.submit-btn').click(function(){
    var secretCode = $('.g-password').val();
    var reg=/^\d{6}$/;
    if(reg.test(secretCode)){ //是6位数字
        $.ajax({
            url:'/user/bind_google_secret.json',
            type:'patch',
            dataType:'json',
            data:{
                secretCode:secretCode
            },
            success:function(data){
                $('.err-info').html('激活成功');
                setTimeout(function(){
                    location.href='/security-center?viewType=page';
                },200);
            },
            error:function(msg){
                $('.err-info').html(JSON.parse(msg.responseText).errors[0].msg);
            }
        });
    }else{
        $('.err-info').html('请输入验证器上的6位数字密码');
    }
});
$('.refresh').click(function(){
    secret();
});